/*
 * File:    Sleep.java
 * Created: 20-Feb-2009
 * Version: $Id$
 *
 * COPYRIGHT (C) 2009, Bitgate Mobile, LLC.  All Rights Reserved.
 *
 * software@bitgatemobile.com
 */

package com.webplasm.render.tags.u;

import java.util.Arrays;
import java.util.List;

import com.webplasm.context.RenderContext;
import com.webplasm.render.engine.RenderException;
import com.webplasm.render.tags.TagInterface;
import com.webplasm.render.tags.WrappedNode;

/**
 * Provides a mechanism to pause rendering for a set amount of time.
 * 
 * @author kenji
 * @since Webplasm 1.0
 */
public class Sleep extends WrappedNode implements TagInterface {
	private static final String DESCRIPTION = "Suspends processing in a page for a certain number of seconds.";

	public String getNamespace() {
		return "u";
	}
	
	public List<String> getAttributes() {
		return Arrays.asList("seconds");
	}
	
	public List<String> getManagedNodes() {
		return null;
	}

	public String getDescription() {
		return DESCRIPTION;
	}

	@Override
	public StringBuffer render(RenderContext rContext) throws RenderException {
		if (elements.get("seconds") == null) {
			throw new RenderException("u:sleep requires seconds to be set.");
		}
		
		try {
			Thread.sleep(Integer.parseInt(elements.get("seconds")) * 1000);
		} catch(Exception ex) {
			throw new RenderException("u:sleep has been interrupted.");
		}
		
		return new StringBuffer();
	}
}